package com.ryan.encrypttool.business.auth.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;

/**
 * @program encrypt-tool
 * @description
 * @author ryan
 * @create 2024-03-12 22:34
 **/
@Configuration
@Slf4j(topic = "rabbitmq")
public class RabbitmqCustomConfig {

    final static String EXCHANGE_NAME = "encrypt-tool-exchange";
    final static String QUEUE_NAME = "encrypt-tool-queue";

    final static String ROUTING_KEY = "encrypt-tool";

    @Bean(EXCHANGE_NAME)
    public DirectExchange createDirectExchange() {
        log.info(EXCHANGE_NAME + " 直连交换机创建成功");
        return new DirectExchange(EXCHANGE_NAME, true, false);
    }

    @Bean(QUEUE_NAME)
    public Queue createQueue() {
        log.info(QUEUE_NAME + " 队列创建成功");
        return new Queue(QUEUE_NAME, true, false, false, null);
    }

    @Bean
    public Binding createBinding() {
        log.info("交换机 {}，队列 {} ，路由 {} 绑定成功", EXCHANGE_NAME, QUEUE_NAME, ROUTING_KEY);
        return new Binding(QUEUE_NAME, Binding.DestinationType.QUEUE, EXCHANGE_NAME, ROUTING_KEY, null);
    }

}
